<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            这题和子集1的区别在于不能有重复元素。比如[1,2,2]  那么[2] [2]是重复的，所以需要去重
            */
            var subsetsWithDup = function (nums) {
                nums.sort((a, b) => a - b)
                let res = []
                let map = new Map()
                function backTracking(path, startIndex) {
                    let str = path.join('')
                    if (!map.has(str)) {
                        res.push([...path])
                        map.set(str, str)
                    }
                    for (let i = startIndex; i < nums.length; i++) {
                        path.push(nums[i])
                        backTracking(path, i + 1)
                        path.pop()
                    }
                }
                backTracking([], 0)
                return res
            }
        </script>
    </body>
</html>
